<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="isall" />
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      v-model="text"
      @keydown.enter="addfn"
    />
  </header>
</template>

<script>
export default {
  props: ["arr"],
  data() {
    return {
      text: "",
    };
  },
  methods: {
    addfn() {
      if (this.text.trim() === "") return alert("输入内容不能为空");
      this.$emit("addtext", this.text);
      this.text = "";
    },
  },
  computed: {
    isall: {
      set(checked) {
        //影响小选框的状态
        this.arr.forEach((item) => (item.isDone = checked));
      },
      get() {
        //小选框统计状态 影响全选框
        // 一个小选框没勾选直接返回fales
        return this.arr.every((obj) => obj.isDone === true);
      },
    },
  },
};
</script>